import RequestUtil from "../utils/RequestUtil";

export const baseUrl = RequestUtil.baseUrl

export function timestampToDateTime(timestamp) {
	const date = new Date(timestamp * 1000);
	const year = date.getFullYear();
	const month = (date.getMonth() + 1).toString().padStart(2, '0');
	const day = date.getDate().toString().padStart(2, '0');
	const hour = date.getHours().toString().padStart(2, '0');
	const minute = date.getMinutes().toString().padStart(2, '0');
	return `${year}-${month}-${day} ${hour}:${minute}`;
}

// 软件列表
export async function fetchSoftList() {
	try {
		const result = await RequestUtil.get('/api/xcx/group_list', {
			group_id: 3
		});
		return result;
	} catch (error) {
		// console.error(error);
		throw error;
	}
}

// 平台列表
export async function fetchPlatformList() {
	try {
		const result = await RequestUtil.get('/api/xcx/group_list', {
			group_id: 2
		});
		return result;
	} catch (error) {
		// console.error(error);
		throw error;
	}
}

// 问题列表
export async function fetchQuestionList() {
	try {
		const result = await RequestUtil.get('/api/xcx/group_list', {
			group_id: 4
		});
		return result;
	} catch (error) {
		// console.error(error);
		throw error;
	}
}

// 详情
export async function fetchContentDetail(id) {
	try {
		const result = await RequestUtil.get('/api/xcx/content_id', {
			id: id
		});
		return result;
	} catch (error) {
		console.error(error);
		throw error;
	}
}
// 获取分组详情
export async function fetchGroupDetail(id) {
	try {
		const result = await RequestUtil.get('/api/xcx/group', {
			id: id
		});
		return result;
	} catch (error) {
		console.error(error);
		throw error;
	}
}

// 获取轮播图
export async function fetchBanner(id) {
	try {
		const result = await RequestUtil.get('/api/xcx/banner', {
			id: id
		});
		return result;
	} catch (error) {
		console.error(error);
		throw error;
	}
}

// 获取轮播图详情
export async function fetchBannerDetail(id) {
	try {
		const result = await RequestUtil.get('/api/xcx/banner_details', {
			id: id
		});
		return result;
	} catch (error) {
		console.error(error);
		throw error;
	}
}



// 小程序分享
export function onShare(title, summary, miniProgramPath) {
	return uni.share({
		provider: 'weixin', // 默认分享平台为微信
		scene: 'WXSceneSession', // 默认分享场景为发送给好友
		type: 5, // 分享类型为小程序
		title: title || '分享标题',
		summary: summary || '分享描述',
		miniProgram: {
			id:  'wx4d16bef7c24ecb9f',
			path: miniProgramPath || 'pages/index/index',
			type:  0,
			webUrl: ''
		},
		success: function(res) {
			console.log('分享成功', res);
			if (options.success) {
				options.success(res);
			}
		},
		fail: function(err) {
			console.error('分享失败', err);
			if (options.fail) {
				options.fail(err);
			}
		}
	});
}